package projectServlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.*;
import dao.mysql.EmployeeDAOFactoryImpl;
import dto.UserDTO;

/**
 * Servlet implementation class StaffDetail
 *
 * @web.servlet
 *   name="StaffDetail"
 *   display-name="StaffDetail"
 *
 * @web.servlet-mapping
 *   url-pattern="/StaffDetailPage"
 */
@WebServlet("/StaffDetailPage")
public class StaffDetail extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public StaffDetail() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doProcess(request,response);	
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		EmployeeDAOFactory eFactory = new EmployeeDAOFactoryImpl();
		UserDTO			   user     = new UserDTO();
		int userID = (int)request.getSession().getAttribute("id");
		try {
			user = eFactory.getEmployeeDAO().findUser(userID);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("userInfo", user);
		RequestDispatcher rd = request.getRequestDispatcher("/StaffDetailPage.jsp");
		rd.forward(request, response);		
		
	}
}
